angular.module('url-interceptor', [])

.run ($ionicPlatform, userData, $localStorage) ->
    $url = location.href
    $qIndex = $url.indexOf('?')
    $hashIndex = $url.indexOf('#')
    
    $urlArr = if $qIndex < $hashIndex then $url.substr($qIndex + 1, $hashIndex - $qIndex - 1).split('&') else $url.substr($qIndex + 1).split('&')
    
    $params = {}
    for $str in $urlArr
        $key = $str.split('=')[0]
        $value = $str.split('=')[1]
        $params[$key] = $value
        if $key == 'token'
            $localStorage.token = $params[$key]
